import React from 'react';
import { Spin, SpinProps, theme } from 'antd';
import styled from 'styled-components';
import ThemeConfig from '@/config/theme';
import { WitIcon } from '@/components/Icon';

const Wrap = styled.div`
  text-align: center;
  padding-block-start: 50vh;
`;

type Props = {
  /**
   * 提示文字
   * @default 数据加载中
   */
  tip?: string;
};
const Loading = (props: Props) => {
  const { tip } = props;
  const { token } = theme.useToken();
  return (
    <Wrap>
      <Spin
        tip={tip}
        delay={50}
        size="large"
        indicator={
          ThemeConfig.loadingSpinner ? (
            <WitIcon spin type={ThemeConfig.loadingSpinner} style={{ color: token.colorPrimary }} />
          ) : undefined
        }
      >
        <span />
      </Spin>
    </Wrap>
  );
};

Loading.defaultProps = { tip: ThemeConfig.loadingText ?? '数据加载中' };
export default Loading;
